<?php
include 'includes.php';


$email = $_POST['Email'];

$password = $_POST['Password'];

$lenusuario = $_POST['User'];


$error = false;
$_SESSION['errorRegistroUser'] = null;
$_SESSION['errorRegistroEmail'] = null;

$rowUser = R::getAll('SELECT * from usuarios where usuario = :usuario', [':usuario' => $lenusuario]);
$rowEmail = R::getAll('SELECT * from usuarios where email = :email', [':email' => $email]);


if (isset($rowUser[0])) {
    $_SESSION['errorRegistroUser'] = "El usuario ya existe";
    $error = true;
}

if (isset($rowEmail[0])) {
    $_SESSION['errorRegistroEmail'] = "El mail ya existe";
    $error = true;
}

if (!$error) {

    $user = R::dispense('usuarios');
    $user->usuario = $lenusuario;
    $user->password =md5($password);
    $user->email = $email;
    $user->permisos = 'miembro';
    R::store($user);
}

$host3 = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'index.php';
header("Location: http://" . $host3 . $uri . "/" . $extra);
die();
?>
